Ext.define('Emp.view.dict.Edit', {
	extend: 'Emp.view.BaseEdit',
	alias: 'widget.dictedit',
	
	requires: [
		'Emp.store.Status'
	],
	
	width: 470,
	height: 300,
	layout: 'border',
	
	initComponent: function() {
		var me = this;
		
		me.gridEditing = Ext.create('Ext.grid.plugin.RowEditing', {
			saveBtnText: '保&nbsp;&nbsp;存',
			cancelBtnText: '取&nbsp;&nbsp;消',
			autoCancel: false
		});
	    
	    var store = Ext.create('Ext.data.JsonStore', {
			model: 'Emp.model.Dictionary'
		});
	    
		me.items = [{
				xtype: 'form',
				region: 'north',
				border: false,
				bodyPadding: '5, 10, 0, 0',
				layout: 'anchor',
				defaults: {
					labelAlign: 'right',
					labelWidth: 50,
					anchor: '100%'
				},
				defaultType: 'textfield',
				items: [{
						fieldLabel: 'id',
						name: 'id',
						hidden: true
					}, {
						xtype: 'fieldcontainer',
						layout: 'hbox',
						anchor: '100%',
						defaults: {
							labelAlign: 'right',
							labelWidth: 60,
							anchor: '100%'
						},
						defaultType: 'textfield',
						items: [{
								fieldLabel: '字典编码',
								name: 'code',
								flex: 1,
								allowBlank: false
							}, {
								fieldLabel: '字典名称',
								name: 'name',
								flex: 1,
								allowBlank: false
						}]
				}]
			}, {
				xtype: 'grid',
				region: 'center',
				border: false,
				title: '字典项',
				store: store,
				columns: [{
						xtype: 'rownumberer',
						width: 40
					}, {
						header: 'id',
						dataIndex: 'id',
						hidden: true,
						hideable: false
					}, {
						header: 'dictId',
						dataIndex: 'dictId',
						hidden: true,
						hideable: false
					}, {
						header: '显示',
						dataIndex: 'display',
						editor: {
			                allowBlank: false
			            },
			            flex: 2
					}, {
						header: '值',
						dataIndex: 'value',
						editor: {
			                allowBlank: false
			            },
			            flex: 2
					}, {
						header: '状态',
						dataIndex: 'status',
						renderer: function(value) {
							return value === 'enable' ? '启用' : '停用';
						},
						editor: {
			                xtype: 'combobox',
							store: Ext.create('Emp.store.Status'),
							queryMode: 'local',
							displayField: 'display',
							valueField: 'value',
							forceSelection: true,
							allowBlank: false
			            },
			            flex: 1
					}, {
						header: '排序',
						dataIndex: 'sort',
						editor: {
							xtype: 'numberfield',
							hideTrigger: true,
							allowDecimals: false,
							allowBlank: false
			            },
			            flex: 1
				}],
		        plugins: [me.gridEditing],
		        tbar: [{
			            text: '增加行',
			            itemId: 'add_row',
						iconCls: 'create'
		        	}, {
			            text: '删除行',
			            itemId: 'delete_row',
						iconCls: 'remove'
		        }]
		}];
		me.callParent();
	}
});